<template>
  <el-dialog
    :visible.sync="param.visible"
    title="修改职位"
    center
    @close="param.close"
    :close-on-click-modal="false"
  >
    <Form1
      ref="editForm"
      :rules="rules"
      :form="editForm"
      :items="items"
      :save="doUpdate"
    >
    </Form1>
  </el-dialog>
</template>
<script>
import Form1 from "@/components/Form1.vue";

export default {
  name: "Edit",
  components: { Form1 },

  props: {
    param: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      editForm: {
        id: "",
        name: "",
        education: "",
        salary: "",
        description: "",
      },
      rules: {
        name: [{ required: true, message: "必填项不能为空" }],
        education: [{ required: true, message: "必填项不能为空" }],
        salary: [{ required: true, message: "必填项不能为空" }],
      },
      items: [
        {
          type: "text",
          label: "职位名称：",
          prop: "name",
          name: "name",
          placeholder: "请输入职位名称",
        },
        {
          type: "text",
          label: "学历要求：",
          prop: "education",
          name: "education",
          placeholder: "请输入学历要求",
        },
        {
          type: "text",
          label: "职位薪水：",
          prop: "salary",
          name: "salary",
          placeholder: "请输入职位薪水",
        },
        {
          type: "area",
          label: "职位描述：",
          prop: "description",
          name: "description",
          placeholder: "请输入职位描述",
        },
      ],
    };
  },
  mounted() {
    this.editForm = JSON.parse(JSON.stringify(this.param.editForm));
  },

  methods: {
    //   修改
    doUpdate() {
      let flag = this.$refs["editForm"].validateForm();
      if (flag) {
        //   保存
        this.putRequest("/post/", this.editForm).then((res) => {
          if (res) {
            this.$message.success(res.message);
            this.param.close(); //关闭
            this.param.callback(); //重新查询
          }
        });
      }
    },
  },
};
</script>
<style></style>
